package com.ruoyi.project.jiaqin.membernewslikes.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.membernewslikes.domain.MemberNewsLikes;
import com.ruoyi.project.jiaqin.membernewslikes.service.IMemberNewsLikesService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户点赞新闻Controller
 *
 * @author admin
 * @date 2021-01-21
 */
@Controller
@RequestMapping("/jiaqin/membernewslikes")
public class MemberNewsLikesController extends BaseController
{
    private String prefix = "jiaqin/membernewslikes";

    @Autowired
    private IMemberNewsLikesService memberNewsLikesService;

    @RequiresPermissions("jiaqin:membernewslikes:view")
    @GetMapping()
    public String membernewslikes()
    {
        return prefix + "/membernewslikes";
    }

    /**
     * 查询用户点赞新闻列表
     */
    @RequiresPermissions("jiaqin:membernewslikes:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MemberNewsLikes memberNewsLikes)
    {
        startPage();
        List<MemberNewsLikes> list = memberNewsLikesService.selectMemberNewsLikesList(memberNewsLikes);
        return getDataTable(list);
    }

    /**
     * 导出用户点赞新闻列表
     */
    @RequiresPermissions("jiaqin:membernewslikes:export")
    @Log(title = "用户点赞新闻", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberNewsLikes memberNewsLikes)
    {
        List<MemberNewsLikes> list = memberNewsLikesService.selectMemberNewsLikesList(memberNewsLikes);
        ExcelUtil<MemberNewsLikes> util = new ExcelUtil<MemberNewsLikes>(MemberNewsLikes.class);
        return util.exportExcel(list, "membernewslikes");
    }

    /**
     * 新增用户点赞新闻
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户点赞新闻
     */
    @RequiresPermissions("jiaqin:membernewslikes:add")
    @Log(title = "用户点赞新闻", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MemberNewsLikes memberNewsLikes)
    {
        return toAjax(memberNewsLikesService.insertMemberNewsLikes(memberNewsLikes));
    }

//    /**
//     * 修改用户点赞新闻
//     */
//    @GetMapping("/edit/{memberId}")
//    public String edit(@PathVariable("memberId") String memberId, ModelMap mmap)
//    {
//        MemberNewsLikes memberNewsLikes = memberNewsLikesService.selectMemberNewsLikesById(memberId);
//        mmap.put("memberNewsLikes", memberNewsLikes);
//        return prefix + "/edit";
//    }

    /**
     * 修改保存用户点赞新闻
     */
    @RequiresPermissions("jiaqin:membernewslikes:edit")
    @Log(title = "用户点赞新闻", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MemberNewsLikes memberNewsLikes)
    {
        return toAjax(memberNewsLikesService.updateMemberNewsLikes(memberNewsLikes));
    }

    /**
     * 删除用户点赞新闻
     */
    @RequiresPermissions("jiaqin:membernewslikes:remove")
    @Log(title = "用户点赞新闻", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(memberNewsLikesService.deleteMemberNewsLikesByIds(ids));
    }
}
